<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/25
 * Time: 17:29
 */

namespace app\http\controller;


use think\worker\Server;
use Workerman\Lib\Timer;
use app\http\controller\PushController as Push;
class WorkerController extends Server
{
    protected $host = '0.0.0.0';
    protected $port = 2346;
    protected $option = [
        'count'		=> 4,
        'name'		=> 'think'
    ];

    public function onMessage($connection, $data)
    {
        $push = new Push;
        $time_interval = 5;
        $connection->timer_id = Timer::add($time_interval, function()use($connection,$push,$data)
        {
            $ret = $push->pushStr($data);
            $connection->send($ret);
        });
    }

    public function onClose($connection){
        // 删除定时器
        Timer::del($connection->timer_id);
    }

}